##
# Notification build script
##

Import('env')

lib_env = env.Clone()
SConscript('#service/third_party_libs.scons', 'lib_env')
notification_sample_env = lib_env.Clone()

target_os = env.get('TARGET_OS')
######################################################################
# Build flags
######################################################################
notification_sample_env.AppendUnique(CPPPATH=[
    '../../include',
    '../../src/common',
    '../../src/provider',
    '#/resource/c_common',
    '#/resource/c_common/oic_malloc/include',
    '#/resource/c_common/oic_string/include',
    '#/resource/csdk/include',
    '#/resource/csdk/stack/include',
    '#/resource/csdk/security/include',
    '#/resource/csdk/resource-directory/include',
    '#/resource/csdk/connectivity/api',
])

notification_sample_env.PrependUnique(LIBS=[
    'resource_directory',
    'octbstack',
    'connectivity_abstraction',
    'oc_logger',
])

if target_os not in ['windows', 'winrt']:
    notification_sample_env.AppendUnique(
        CXXFLAGS=['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])

if target_os not in ['darwin', 'ios', 'windows', 'winrt']:
    notification_sample_env.AppendUnique(LINKFLAGS=['-Wl,--no-undefined'])

if target_os == 'linux':
    notification_sample_env.AppendUnique(LIBS=['pthread'])

if target_os == 'android':
    notification_sample_env.AppendUnique(CXXFLAGS=['-frtti', '-fexceptions'])
    notification_sample_env.AppendUnique(LIBS=['gnustl_shared', 'log'])

    if not env.get('RELEASE'):
        notification_sample_env.AppendUnique(LIBS=['log'])

notification_sample_consumer_src = 'notificationconsumer.c'
notification_sample_provider_src = 'notificationprovider.c'

if env.get('WITH_CLOUD') == True:
    notification_sample_env.AppendUnique(CPPPATH=['../../src/consumer'])
    notification_sample_env.AppendUnique(CPPPATH=['../../src/provider'])

    providerCloudConnectorObj = notification_sample_env.Object('cloud_connector.c')
    consumerCloudConnectorObj = notification_sample_env.Object('cloud_connector.c')

    #PROVIDER_CLOUD = File('cloud_connector.c')
    #notification_sample_provider_src = ['notificationprovider.c', PROVIDER_CLOUD]
    notification_sample_provider_src = [
        'notificationprovider.c',
        providerCloudConnectorObj,
    ]
    #CONSUMER_CLOUD = File('cloud_connector.c')
    #notification_sample_consumer_src = ['notificationconsumer.c', CONSUMER_CLOUD]
    notification_sample_consumer_src = [
        'notificationconsumer.c',
        consumerCloudConnectorObj,
    ]

if env.get('SECURED') == '1':
    notification_sample_env.AppendUnique(
        LIBS=['mbedtls', 'mbedx509', 'mbedcrypto'])



####################################################################
# Source files and Targets
######################################################################
examples = []
notification_sample_provider_env = notification_sample_env.Clone()
notification_sample_provider_env.AppendUnique(LIBS='libnotification_provider')
notificationprovider = notification_sample_provider_env.Program(
    'notificationprovider', notification_sample_provider_src)
i_notificationprovider = notification_sample_provider_env.Install(
    env.get('BUILD_DIR'), notificationprovider)
examples += notificationprovider

notification_sample_consumer_env = notification_sample_env.Clone()
notification_sample_consumer_env.AppendUnique(LIBS='libnotification_consumer')
notificationconsumer = notification_sample_consumer_env.Program(
    'notificationconsumer', notification_sample_consumer_src)
i_notificationprovider = notification_sample_consumer_env.Install(
    env.get('BUILD_DIR'), notificationconsumer)
examples += notificationconsumer

if env.get('WITH_CLOUD') == True:
    Export('providerCloudConnectorObj')
    Export('consumerCloudConnectorObj')

notification_sample_consumer_env.UserInstallTargetExtra(examples)
